package com.hyjx.framework.component.codetable;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.orm.dao.IBaseDao;
import com.hyjx.framework.orm.dao.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;

/**
 * 码表类别服务实现类
 */
@Service
@Transactional
public class CodeTableManagerServiceImpl implements CodeTableManagerService {
    @Resource
    private IBaseDao dao;

    @Override
    public String queryList(CodeTableManagerModel model) {
        Pager pager = dao.getPager(model.getModuleName() + ".queryList", model.getModuleName() + ".queryCount", model);

        return CommonUtil.getPageJsonStr(pager);
    }

    @Override
    public boolean add(CodeTableManagerModel model) {
        return dao.addObject(model.getModuleName() + ".insert", model);
    }

    @Override
    public CodeTableManagerModel getInfoById(String s) {
        return (CodeTableManagerModel) dao.queryObject((new CodeTableManagerModel()).getModuleName() + ".getInfoById", s);
    }

    @Override
    public int edit(CodeTableManagerModel model) {
        return dao.updateObject(model.getModuleName() + ".update", model);
    }

    @Override
    public int delete(String ids) {
        String[] id_array = ids.split(",");
        int num = 0;
        for (String id : id_array) {
            dao.deleteObject((new CodeTableManagerModel()).getModuleName() + ".delete", id);
            num++;
        }
        return num;
    }

    @Override
    public int checkcodetable(String codetable) throws SQLException {
        return (Integer) dao.queryObject((new CodeTableManagerModel()).getModuleName() + ".checkcodetable", codetable);
    }
}
